package com.exam.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

import com.exam.model.StudentModel;
/**
 * 
 * author: 刘楠
 */
public class JXLImportUtils {
	
	
	public static List<StudentModel> getStudent(File file){
		List<StudentModel> list = new ArrayList<StudentModel>();
		try {
			Workbook book = Workbook.getWorkbook(file);
			// 获得第一个工作表对象
			Sheet sheet = book.getSheet(0);
			int rows = sheet.getRows();
			int columns = sheet.getColumns();
			// 遍历每行每列的单元格
			for (int i = 3; i < rows; i++) {
				StudentModel studentModel = new StudentModel();
				for (int j = 0; j < columns; j++) {
					Cell cell = sheet.getCell(j, i);
					String result = cell.getContents();
					if (j == 0) {
						studentModel.setStu_id(result);
					}
					if (j == 1) {
						if(result != null){
							studentModel.setGid(Integer.parseInt(result.trim()));
						}
					}
					if (j == 2) {
						studentModel.setStu_name(result);
					}
				}
				list.add(studentModel);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
